package com.mb.api.controller;

import com.google.gson.Gson;
import com.mb.api.service.IMemberService;
import com.mb.app.domain.TbMemberInfo;
import com.mb.common.utils.R;
import com.mb.oa.service.NotifyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 会员信息处理
 *
 * @author zwl
 * @create 2019-03-11 8:53 AM
 **/
@Controller
@RequestMapping("/api/member")
@Slf4j
public class TBMemberController {

    @Autowired
    private IMemberService memberService;

    @Autowired
    private NotifyService notifyService;

    /**
     * 提交用户信息
     * @param data
     * @param request
     * @return
     */
    @ResponseBody
    @PostMapping("/submit")
    public R submit(@RequestBody String data,HttpServletRequest request){
        Gson gson=  new Gson();
        TbMemberInfo memberInfo = gson.fromJson(data, TbMemberInfo.class);
        int instr = memberService.submit(memberInfo);
        if (instr == 1) {
            return R.ok();
        }else {
            return R.error();
        }
    }

    /**
     * 获取通知公告
     * @param request
     * @return
     */
    @ResponseBody
    @GetMapping("/getNotifyList")
    public R getNotifyList(HttpServletRequest request){
        Map<String,Object> data = notifyService.getNotifyList();
        if (data != null) {
            return R.ok(data);
        }else {
            return R.error();
        }
    }




}
